package com.anuyun.ms.ums.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.anuyun.ms.base.annotation.Log;
import com.anuyun.ms.base.annotation.RestExceptionHandler;
import com.anuyun.ms.base.common.Result;
import com.anuyun.ms.ums.entity.User;
import com.anuyun.ms.ums.service.UserService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

@RestController
@RestExceptionHandler
@RequestMapping("user")
public class UserController {

	@Autowired
	UserService userService;

	@PostMapping("")
	@Log(value = "新增用户")
	public Result<Object> insert(@RequestBody User user) {
		user = userService.insert(user);
		return new Result<>(user);
	}

	@GetMapping("{id}")
	@Log(value = "查询用户")
	public Result<User> get(@PathVariable String id) {
		User user = userService.get(id);
		return new Result<>(user);
	}
	
	@PostMapping("list")
	public Result<Page<User>> list(@RequestBody Map<String,String> queryVO){
		
		Page<User> users= userService.list(queryVO);
		return new Result<>(users);
	}
	
	

	@PostMapping("login")
	@Log(value = "用户登录")
	public Result<Map<String, Object>> login(@RequestBody User user) {
		Map<String, Object> reslut = userService.login(user);
		return new Result<>(reslut);
	}

	@GetMapping("heartbeat")
	@Log(value = "心跳检测")
	public Result<String> heartbeat() {
		return new Result<String>("I'm ok");
	}

}
